package com.property.manage.configuration;

import com.guardchina.framework.auth.jwt.JsonWebToken;
import com.guardchina.framework.web.filter.LoginFilter;
import com.guardchina.framework.web.impl.TokenForceExpValidator;
import com.guardchina.framework.web.model.TokenValidatorHolder;
import com.guardchina.framework.web.properties.LoginProperties;
import com.property.manage.filter.AuthFilter;
import com.property.manage.properties.AuthProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/3/24
 */
@Configuration
public class WebConfiguration {

    /*@Bean
    public TokenForceExpValidator tokenForceExpValidator(LoginProperties loginProperties){
        return new TokenForceExpValidator(loginProperties);
    }

    @Bean
    public TokenValidatorHolder tokenValidatorHolder(TokenForceExpValidator tokenForceExpValidator){
        TokenValidatorHolder tokenValidatorHolder = new TokenValidatorHolder();
        tokenValidatorHolder.addValidator(tokenForceExpValidator);
        return tokenValidatorHolder;
    }*/

    @Bean
    public FilterRegistrationBean authFilterRegistration(AuthProperties authProperties){
        FilterRegistrationBean<AuthFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new AuthFilter(authProperties));
        registration.addUrlPatterns("/*");
        registration.setName("authFilter");
        registration.setOrder(2);
        return registration;
    }

    @Bean
    public FilterRegistrationBean userLoginFilterRegistration(JsonWebToken jsonWebToken, LoginProperties loginProperties){
        FilterRegistrationBean<LoginFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new LoginFilter(jsonWebToken, null, loginProperties));
        registration.addUrlPatterns("/*");
        registration.setName("userLogFilter");
        registration.setOrder(3);
        return registration;
    }
}
